package cn.fl.spl.service.impl;

import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.logger.eum.LogOperEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.spl.service.ISplRankInfoService;
import cn.fl.spl.transform.SplRankInfoVOTransform;
import cn.fl.spl.vo.SplRankInfoVO;
import fl.constant.facade.framework.constant.BusinessIdConstant;
import fl.mongo.facade.analysis.api.ISplRankInfoApiService;
import fl.mongo.facade.analysis.api.ISplRankInfoQueryApiService;
import fl.mongo.facade.analysis.condition.SplRankInfoCondition;
import fl.spl.facade.framework.constant.SplSystemConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by jiangzhongge on 2018-3-8.
 * Time 21:16.
 * Class belongs to fl-ass-service.
 */
@Service
public class SplRankInfoServiceImpl implements ISplRankInfoService {

    @Autowired
    private ISplRankInfoApiService splRankInfoApiService ;

    @Autowired
    private ISplRankInfoQueryApiService splRankInfoQueryApiService ;

    @Override
    public List<SplRankInfoVO> getSplRankInfoList(SplRankInfoCondition condition) throws BaseException {
        if(null == condition){
            BaseLogUtils.newWebLogger("查询排名信息List，条件参数不能为空").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
            return null;
        }
        return SplRankInfoVOTransform.toVOList(this.splRankInfoQueryApiService.getSplRankInfoList(condition));
    }

    @Override
    public int addSplRankInfo(SplRankInfoVO splRankInfoVO) throws BaseException {
        if(null == splRankInfoVO){
            BaseLogUtils.newWebLogger("查询排名信息，条件参数不能为空").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
            return 0;
        }
        return this.splRankInfoApiService.addSplRankInfo(SplRankInfoVOTransform.toDTO(splRankInfoVO));
    }

    @Override
    public int batchAddSplRankInfo(List<SplRankInfoVO> splRankInfoVOs) throws BaseException {
        if(CollectionUtils.isEmpty(splRankInfoVOs)){
            BaseLogUtils.newWebLogger("批量插入排名信息,参数为空").setLogOperType(LogOperEnum.REQ)
                    .setSysCd(CurrentThreadContext.getCurrentSysCd())
                    .setChannelCd(SplSystemConstant.FL_WEB_CHL_CD)
                    .setBussinessId(BusinessIdConstant.LOG_SPL_MANAGER_CD)
                    .setWarning(false)
                    .warn(LogExceptionEnum.COMMON_CODE_0002);
            return 0 ;
        }
        return this.splRankInfoApiService.batchAddSplRankInfo(SplRankInfoVOTransform.toDTOList(splRankInfoVOs));
    }
}